package com.glela.task;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import com.glela.common.util.DateUtil;
import com.glela.platform.model.BaseRestrictions;
import com.glela.platform.service.BaseRestrictionsService;
import com.glela.statistics.mapper.OrderStatisticsMapper;
import com.glela.statistics.model.OrderCondition;
import com.glela.talent.util.MyDateUtil;

/**
 * 自动统计订单
 * @author MaoZeYao
 *
 */
public class OrderStatisticsTask {
	
	@Autowired
	private OrderStatisticsMapper orderStatisticsMapper;
	@Autowired
	private BaseRestrictionsService baseRestrictionsService;
	
	private static MyDateUtil util = MyDateUtil.INSTANCE;

	public void initializeTableReport() {
		
		OrderCondition condition = new OrderCondition();
		condition.setCurrentTime(util.getYesterday(new Date()));
		condition.setSevenTime(util.getOldDays(7));
		condition.setThityTime(util.getOldDays(30));
		condition.setNinetyTime(util.getOldDays(90));
		
		/**
		 * 初始化讲师订单数量
		 */
		orderStatisticsMapper.initializeTableOrderReport(condition);
		
		/**
		 * 初始化讲师推客所属订单
		 */
		orderStatisticsMapper.initializeTableTalentOrderQuantityReport(condition);
		
		/**
		 * 初始化讲师佣金
		 */
		orderStatisticsMapper.initializeTableCommisomnReport(condition);
		
		/**
		 * 初始化讲师销售额区间统计
		 */
		orderStatisticsMapper.initializeTableSalesAmountReport(condition);
		
		/**
		 * 初始化讲师月销售明细
		 */
		orderStatisticsMapper.initializeTableSalesMonthReport(condition);
		
		condition.setCurrentTime(util.getYesterday(new Date()));
		/**
		 * 初始化订单销量
		 */
		BaseRestrictions baseRestrictions=baseRestrictionsService.getBaseRestrictionsForCache("goods_sales_count_limit");	
		if(baseRestrictions!=null){
			orderStatisticsMapper.initializeGoodsSalesCount(
					util.getOldDays(baseRestrictions.getExperience()),util.getOldDays(0),baseRestrictions.getExperience());
		}
		
	}


}
